package kr.makjang.lib.util;

import java.util.regex.Pattern;

/**
 * 특정 스트링 값을 받아와서 정규표현식에 의해 체크하기 위한 클래스
 * @date 2011-12-08
 * @author Claude.H
 *
 */
public class MakCheckValue
{
    private final Pattern EMAIL_PATTERN = Pattern
            .compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@"
                    + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\."
                    + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+");
    
    private final Pattern IP_PATTERN = Pattern
            .compile("^(1|2)?[0-9]?[0-9]([.](1|2)?[0-9]?[0-9]){3}$");
    
    private final Pattern MAC_ADDRESS_PATTERN = Pattern
            .compile("[0-9a-fA-F]{2}[-:][0-9a-fA-F]{2}[-:][0-9a-fA-F]{2}[-:]" +
                     "[0-9a-fA-F]{2}[-:][0 -9a-fA-F]{2}[-:][0-9a-fA-F]{2}");
    
    
    private final Pattern PHONE_NUMBER_PATTERN = Pattern
            .compile("^(01\\d{1}|02|0505|0502|0506|0\\d{1,2})-?(\\d{3,4})-?(\\d{4})");
    
    /**
     * Constructor
     */
    public MakCheckValue(){ }
    
    /**
     * Email의 유효성 체크
     * @param email
     * @return
     */
    public boolean checkEmailFormat(String email)
    {
        return EMAIL_PATTERN.matcher(email).matches();
    }
    
    /**
     * IP의 유효성 체크
     * 
     * @param ip
     * @return
     */
    public boolean checkIPFormat(String ip)
    {
        return IP_PATTERN.matcher(ip).matches();
    }
    
    /**
     * Mac Address의 유효성 체크
     * @param macAddress
     * @return
     */
    public boolean checkMacAddressFormat(String macAddress)
    {
        return MAC_ADDRESS_PATTERN.matcher(macAddress).matches();
    }
    
    /**
     * 일반전화, 휴대전화의 유효성 체크
     * ex) 02-897-4878, 032-897-4878, 028974878, 010-1234-5678
     * @param phone_number
     * @return
     */
    public boolean checkPhoneNumberFormat(String phone_number)
    {
        return PHONE_NUMBER_PATTERN.matcher(phone_number).matches();
    }
}